package com.qk.management.service.impl;

import com.qk.common.PageResult;
import com.qk.entity.Activity;
import com.qk.management.mapper.ActivityMapper;
import com.qk.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public PageResult<Activity> page(Integer channel, Integer type, Integer status, Integer page, Integer pageSize) {
        Integer total = activityMapper.count(channel,type,status);
        Integer offSet =(page-1)*pageSize;
        List<Activity> rows = activityMapper.selectByPage(channel,type,status,offSet,pageSize);
        return PageResult.<Activity>builder().total(total).rows(rows).build();
    }

    @Override
    public List<Activity> findByType(Integer type) {
        List<Activity> activitys = activityMapper.findByType(type);
        return activitys;
    }

    @Override
    public void update(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.update(activity);
    }

    @Override
    public Activity findById(Integer id) {
        return activityMapper.findById(id);
    }

    @Override
    public void add(Activity activity) {
        activity.setCreateTime(LocalDateTime.now());
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.add(activity);
    }

    @Override
    public void deleteById(Integer id) {
        activityMapper.deleteById(id);
    }
}
